package com.video.list.player

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.video.list.player.bean.VideoInfo
import com.video.list.player.fragment.VideoFragment

class VideoPageFragmentAdapter(activity: FragmentActivity) :
    FragmentStateAdapter(activity) {

    val data = mutableListOf<VideoInfo>()

    fun setNewData(newData: Collection<VideoInfo>) {
        data.clear()
        data.addAll(newData)
        notifyDataSetChanged()
    }

    override fun getItemCount(): Int {
        return data.size
    }

    override fun createFragment(position: Int): Fragment {
        return VideoFragment.newInstance(data[position])
    }
}